<template>
  <div id="app">
    <router-view></router-view>

    <van-tabbar v-show="$route.meta.isShow" v-model="active" active-color="#ee0a24" inactive-color="#000" z-index="999">
      <van-tabbar-item to="/home" icon="wap-home-o">首页</van-tabbar-item>
      <van-tabbar-item to="/category" icon="apps-o">分类</van-tabbar-item>
      <van-tabbar-item to="/worthbuy" icon="photo-o">值得买</van-tabbar-item>
      <van-tabbar-item to="/cart" icon="cart-o">购物车</van-tabbar-item>
      <van-tabbar-item to="/center" icon="user-o">个人</van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
const paths = ['/home', '/category', '/worthbuy', '/cart', '/center']
export default {
  name: 'App',
  data() {
    return {
      active: 0,
    }
  },
  mounted() {
    // 解决刷新时不能选中底部对应的tab的bug
    setTimeout(() => {
      // console.log('---', this.$route)
      this.active = paths.indexOf(this.$route.path)
    }, 50);
    // this.active = paths.indexOf(this.$route.path)
    this.$bus.$on('setActive', this.setActive)
  },
  methods: {
    setActive(num){
      this.active = num;
    }
  },

  watch: {
    $route () {
      const path = this.$route.path
      this.active = paths.indexOf(path)
    }
  }
}
</script>

<style lang="scss">


</style>
